@extends('layouts.app')

@section('content')
<div class="content-header">
    <h1>权限设置</h1>
    <ol class="breadcrumb">
      <li><a href="{{ url('/') }}"><i class="fa fa-dashboard"></i> 首页</a></li>
      <li class="active">权限设置</li>
    </ol>
  </div>
<div class="content">
    <div class="row">
        @if (count($errors) > 0)
            <div class="alert alert-danger" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <ul>
                @foreach ($errors->all() as $error)
                  <li>{{ $error }}</li>
                @endforeach
                </ul>
            </div>
        @endif
        <div class="col-md-12">
            <div class="panel panel-primary">
                <div class="panel-heading">权限设置</div>

                <div class="panel-body">
                    <table class="table table-striped table-hover">
                        <thead>
                            <tr>
                                <th>用户</th>
                                <th>是否有部署权限</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach ($users as $user)
                                <tr>
                                    <td>{{ $user->name }}（{{ $user->gitlab_nickname }}）</td>
                                    <td>
                                        <form method="post">
                                            {!! csrf_field() !!}
                                            <input type="hidden" name="user_id" value="{{ $user->id }}">
                                            <input class="checkbox" {{ $user->can($permission_name) ? 'checked' : '' }} {{ $user->hasRole('owner') ? 'checked disabled' : ''  }} type="checkbox">
                                        </form>
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
    

<script src="https://cdn.jsdelivr.net/jquery/1.11.3/jquery.min.js"></script>
<script>
    $(function () {
        $('input[type="checkbox"]').change(function () {
            $(this).parent().submit();
        });
    })
</script>
@endsection
